import { identity, isEmpty, isNumber, pickBy } from 'lodash';
import request from '@/http/request';
import { IQueryParams } from '@/widgets/table-pagination';
import Qs from 'qs';

export function getList(queryParams: IQueryParams) {
  let filterParam: any = {
    ...queryParams,
    ...pickBy(queryParams.filter, (value) => {
      return !isEmpty(value);
    }),
    ...pickBy(queryParams.filter, isNumber),
  };
  filterParam.page = filterParam.pageNum - 1;
  filterParam.size = filterParam.pageSize;
  delete filterParam.filter;
  delete filterParam.pageNum;
  delete filterParam.pageSize;

  const param = Qs.stringify(filterParam);
  return request.get(`/point/getPage?${param}`);
}

export function deleteItem(id: number) {
  return request.delete(`/admin-api/system/dept/delete?id=${id}`);
}

export function createItem(entity: any) {
  return request.post(`/admin-api/system/dept/create`, entity);
}

export function updateItem(entity: any) {
  return request.post(`/point/confirm`, entity);
}
